// pages/classifylist/classifylist.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    videoNum: 1,
    query:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let EventChannel = this.getOpenerEventChannel();
    EventChannel.on("tab", (data) => {
      this.getData(data)
      this.setData({
        query:data,
      })
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    //获取第二组数据
    this.setData({
      videoNum:this.data.videoNum+1,
    })
    this.getData(this.data.query);
  },
  getData(data) {
    let key = Object.keys(data);
    let value = Object.values(data);
    let url = `https://app.vmovier.com/apiv3/post/getPostInCate?p=${this.data.videoNum}&size=10&${key}=${value}`
    if (/hot|album/.test(value)) {
      url = `https://app.vmovier.com/apiv3/post/getPostByTab?p=${this.data.videoNum}&size=10&${key}=${value}`
    } else if (value.includes('Series')) {
      url = `https://app.vmovier.com/apiv3/series/getList?p=${this.data.videoNum}&size=10`
    }
    wx.request({
      url: url,
      success: (res) => {
        this.setData({
          list: [...this.data.list,...res.data.data],
        })
      }
    })
  },
})